module pet {
	export class Req  {
		//协议id
		public pid:number;
		public data:any;
		public constructor() {
			if( Req._new_lock) throw new Error('Use Req.getReq() instean pls.');
		}
		public reset(){
			this.pid = 0;
			this.data = null;
		}
		
		public static destroy(){
			while(Req._cache && Req._cache.length){
				let req = Req._cache.pop();
				req = null;
			}
			Req._cache = null;
		}

		private static _new_lock:boolean = true;
		private static _cache:Req[];
		public static getReq():Req{
			if( Req._cache == null) Req._cache = [];
			while(Req._cache.length){
				return Req._cache.pop();
			}
			Req._new_lock= false;
			let req:Req = new Req();
			Req._new_lock= true;
			return req;
		}

		public static recycleReq(req:Req){
			req.reset();
			if(Req._cache.indexOf(req) == -1) Req._cache.push(req);
		}
	}
}